package io.renren.service.impl;

import io.renren.entity.dto.MenuBookVideoDto;
import io.renren.entity.vo.BookVideo4Show;
import io.renren.utils.ConfigConstant;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import io.renren.dao.BookVideoDao;
import io.renren.entity.BookVideo;
import io.renren.service.BookVideoService;


@Service("bookVideoService")
public class BookVideoServiceImpl implements BookVideoService {
    @Resource
    private BookVideoDao bookVideoDao;

    @Override
    public Map<Long, Map<Long, List<MenuBookVideoDto>>> getSubjectVersionVideoMap(Long gradeId) {
        List<MenuBookVideoDto> menuBookVideoDtos = bookVideoDao.queryBookVideo4All(gradeId,
                Long.parseLong(ConfigConstant.DEFAULT_SEASON_ID));
        return menuBookVideoDtos.stream()
                .sorted(Comparator.comparing(MenuBookVideoDto::getPageNo)
                        .thenComparing(MenuBookVideoDto::getOrderField))
                .collect(Collectors.groupingBy(MenuBookVideoDto::getSubjectId,
                        Collectors.groupingBy(MenuBookVideoDto::getVersionId)));
    }

    @Override
    public BookVideo queryObject(Long id) {
        return bookVideoDao.queryObject(id);
    }

    @Override
    public List<BookVideo> queryList(Map<String, Object> map) {
        return bookVideoDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return bookVideoDao.queryTotal(map);
    }

    @Override
    public List<BookVideo> queryList4Query(Map<String, Object> map) {
        return bookVideoDao.queryList4Query(map);
    }

    @Override
    public int queryTotal4Query(Map<String, Object> map) {
        return bookVideoDao.queryTotal4Query(map);
    }

    @Override
    public List<BookVideo4Show> queryList4ListQuery(Map<String, Object> map) {
        return bookVideoDao.queryList4ListQuery(map);
    }

    @Override
    public int queryTotal4ListQuery(Map<String, Object> map) {
        return bookVideoDao.queryTotal4ListQuery(map);
    }

    @Override
    public void save(BookVideo bookVideo) {
            bookVideoDao.save(bookVideo);
    }

    @Override
    public void saveBatch(List<BookVideo> bookVideoList) {
        bookVideoDao.saveBatch(bookVideoList);
    }

    @Override
    public void update(BookVideo bookVideo) {
            bookVideoDao.update(bookVideo);
    }

    @Override
    public void delete(Long id) {
            bookVideoDao.delete(id);
    }

    @Override
    public void deleteBatch(Long[]ids) {
            bookVideoDao.deleteBatch(ids);
    }

    @Override
    public void updateBatch(List<BookVideo> bookVideoList) {
        bookVideoDao.updateBatch(bookVideoList);
    }

}
